﻿#region Header
//
//   Project:           SilverShader - Silverlight pixel shader demo application for Coding4Fun.
//
//   Changed by:        $Author$
//   Changed on:        $Date$
//   Changed in:        $Revision$
//   Project:           $URL$
//   Id:                $Id$
//
//
//   Copyright (c) 2010 Rene Schulte
//
//   This program is open source software. Please read the License.txt.
//
#endregion

using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Windows.Controls;
using System.Windows.Media.Effects;
using Schulte.Silverlight.Shader;
using SilverShader.Views;
using System.Windows;

namespace SilverShader.ViewModels
{
   /// <summary>
   /// The view model for the mosaic shader.
   /// </summary>
   [Export]
   public class MosaicShaderViewModel : AbstractViewModel, INotifyPropertyChanged
   {
      readonly MosaicShaderEffect shader;

      public override string Name
      {
         get { return "Mosaic"; }
      }

      public override ShaderEffect Shader
      {
         get { return shader; }
      }

      [Import(typeof(MosaicShaderPage))]
      public override UserControl View { get; set; }

      public float BlockCount
      {
         get { return shader.BlockCount; }
         set
         {
            shader.BlockCount = value;
            OnPropertyChanged(new PropertyChangedEventArgs("BlockCount"));
         }
      }

      public float MinDistance
      {
         get { return shader.Min; }
         set
         {
            shader.Min = value;
            OnPropertyChanged(new PropertyChangedEventArgs("MinDistance"));
         }
      }

      public float MaxDistance
      {
         get { return shader.Max; }
         set
         {
            shader.Max = value;
            OnPropertyChanged(new PropertyChangedEventArgs("MaxDistance"));
         }
      }

      public override Point InputSize
      {
         get
         {
            return base.InputSize;
         }
         set
         {
            base.InputSize = value;
            shader.AspectRatio = (float)(value.X / value.Y);
         }
      }

      public MosaicShaderViewModel()
      {
         // Model
         shader = new MosaicShaderEffect();

         // View is wired up with MEF
      }
   }
}
